Skip to content

fix: resolve plot graph div for react-plotly.js v4 ref change#55

Merged
Flint8777 merged 1 commit into
mainfrom
fix/react-plotly4-ref-el
Jun 20, 2026
Merged

fix: resolve plot graph div for react-plotly.js v4 ref change#55
Flint8777 merged 1 commit into
mainfrom
fix/react-plotly4-ref-el

Conversation

@Flint8777

Copy link
Copy Markdown
Owner

不具合

react-plotly.js 4.0.0(#53)へ上げた後、EXE でスペクトルを読み込んでもクロスヘアが表示されないとの報告。

原因

react-plotly.js v4 は forwardRef 関数コンポーネントになり、ref が Plotly のグラフ div を直接指すようになった。v2 のクラスインスタンス(.el に DOM を保持)とは異なる。

App.jsx は全箇所で plotRef.current.el を参照しており、v4 では undefined に化けるため:

  • mousemove リスナが張れず → クロスヘア表示されず
  • 座標表示(dataCoord_fullLayout 参照)が機能せず
  • plotly_relayout 直接購読が張れず → ズーム検知(Reset Zoom ボタン enable)が機能せず

修正

getPlotEl() = plotRef.current?.el ?? plotRef.current を追加し、v2/v4 両対応でグラフ div を取り出す。7箇所の plotRef.current.el を全て置換。

検証(vite dev + Playwright)

OPUS ファイル読込後:

  • mousemove で .crosshair-layer 出現、座標表示 "1.7255 μm"
  • Plotly.relayout でズーム → "Reset Zoom" ボタンが enabled
  • npm run test:run 44 件 pass

赤いクロスヘア + 座標表示(X: 3.5224 μm · Y: 0.3119)をローカルで目視確認済み。

🤖 Generated with Claude Code

react-plotly.js v4 became a forwardRef function component whose ref
points directly at the Plotly graph div, dropping the v2 class-instance
`.el` property. Every `plotRef.current.el` access silently became
undefined, so the mousemove listener, coordinate readout, and the
plotly_relayout zoom subscription never attached.

Symptom: after loading a spectrum the crosshair (and coordinate
readout / Reset Zoom enable) no longer appeared.

Add getPlotEl() = `plotRef.current?.el ?? plotRef.current` (works on
both v2 and v4) and route all 7 call sites through it.

Verified via Playwright on vite dev with an OPUS file:
- mousemove renders .crosshair-layer; readout shows "1.7255 μm"
- Plotly.relayout to a zoomed range enables the Reset Zoom button
- 44 unit tests pass

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BL1jdGKYgu4YKDQ8KJVGKX
@github-actions

Copy link
Copy Markdown

✅ macOS build check passed

@github-actions

Copy link
Copy Markdown

✅ Windows build check passed

@Flint8777 Flint8777 merged commit d7d351a into main Jun 20, 2026
5 checks passed
@Flint8777 Flint8777 deleted the fix/react-plotly4-ref-el branch June 20, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant